<?php
/**
 * ClassName: PaymentLogService
 * Description: 线下支付 service
 * @Author 周昌
 * @Create 2023/12/25 16:37
 */

namespace service\admin;


use service\BaseService;

class PaymentLogService extends BaseService
{
    protected static $model = 'model\PaymentLogModel';
    public static $payment_log_type = ['治疗服务', '取药'];
    public static $payment_log_type_index = ['treatment' => 0, 'take_medicine' => 1];
    //线下支付类型下拉select选择
    public static function payLogTypeSelect()
    {
        static $payment_log_type_select;
        if(empty($payment_log_type_select)){
            foreach (self::$payment_log_type as $k=>$v){
                $row=[];
                $row['id']=$k;
                $row['name']=$v;
                $payment_log_type_select[]=$row;
            }
            array_unshift($payment_log_type_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $payment_log_type_select;
    }
    /**
     * #User: Administrator
     * #Time: 2023/12/26 14:46
     * #Author:周昌
     * #Description:添加线下支付记录
     * @param array $data  case_id,type,member_id,money
     * @return array
     */
    public static function addPaymentLog($data)
    {
        $data['hospital_id'] = self::getUserHospitalId();
        switch ($data['type']) {
            case 0:
                $data['desc'] =$data['desc']?? '治疗服务线下支付' . $data['money'] . '元';
                break;
            case 1:
                $data['desc'] = $data['desc']?? '取药线下支付' . $data['money'] . '元';
                break;
        }
        $data['addtime'] = time();
        return self::add($data);
    }
    //列表数据
    public static function getAjaxData($where)
    {
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['type_name']=self::$payment_log_type[$data['type']];
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],''):'';
            return $data;
        });
    }
}